# -*- coding:utf-8 -*-
import logging.config
import os
import sys

__author__ = 'gin.chen'


class Properties(object):
    def __init__(self, file_name):
        self.fileName = file_name
        self.properties = {}
        with open(self.fileName, 'r') as pro_file:
            for line in pro_file.readlines():
                line = line.strip().replace('\n', '')
                if line.find("#") != -1:
                    line = line[0:line.find('#')]
                if line.find('=') > 0:
                    strs = line.split('=')
                    strs[1] = line[len(strs[0]) + 1:]
                    self.properties[strs[0].strip()] = strs[1].strip()

    def get_properties(self):
        return self.properties

    def to_string(self):
        logger.info(self.properties)


__mysql_config_file = os.path.join(os.path.dirname(__file__), 'mysql.config')
__http_config_file = os.path.join(os.path.dirname(__file__), 'http.config')
__user_config_file = os.path.join(os.path.dirname(__file__), 'user-mapping.config')
__redis_config_file = os.path.join(os.path.dirname(__file__), 'redis.config')
config_http = Properties(__http_config_file).get_properties()
config_user = Properties(__user_config_file).get_properties()
log_path = os.path.abspath(os.path.dirname(sys.argv[0]))+'/config.ini'
logging.config.fileConfig(log_path)
logger = logging.getLogger('fileLogger')
path = os.path.abspath(os.path.dirname(sys.argv[0])) + '/exec_id.txt'


